//
//  PTSBaseNavigationController.m
//  PTS80
//
//  Created by 黄杰 on 15/11/2.
//  Copyright © 2015年 黄杰. All rights reserved.
//

#import "PTSBaseNavigationController.h"
#import "UIImage+My.h"
#import "PTSTabBarViewController.h"
#import "UINavigationController+FDFullscreenPopGesture.h"

#define IOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)

@interface PTSBaseNavigationController ()

@end

@implementation PTSBaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //    self.canDragBack = YES;
//    self.delegate = self;
//    self.interactivePopGestureRecognizer.delegate = self;
    //    __weak typeof (self) weakSelf = self;
    //    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    //        self.interactivePopGestureRecognizer.delegate = weakSelf;
    //    }
}

+ (void)initialize
{
    // 1.NavigationBar主题
    [self setupNavigationBar];
    
    // 2.UIBarButtonItem主题
    [self setupBarButtonItem];
}

#pragma mark - 设置NavigationBar主题
+ (void)setupNavigationBar
{
    UINavigationBar *navBar = [UINavigationBar appearance];
    // 设置导航栏背景
    [navBar setBackgroundImage:[UIImage resizeWithImageName:@"PTS80.bundle/nav"] forBarMetrics:UIBarMetricsDefault];
    navBar.shadowImage = [UIImage new];
    navBar.tintColor = [UIColor whiteColor];
    
    // 设置标题字体
    NSMutableDictionary *titleAttr = [NSMutableDictionary dictionary];
    titleAttr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    titleAttr[NSFontAttributeName] = [UIFont systemFontOfSize:18];
    [navBar setTitleTextAttributes:titleAttr];
}

+ (void)setupBarButtonItem
{
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    // 设置导航栏字体颜色
    NSMutableDictionary *itemAttr = [NSMutableDictionary dictionary];
    itemAttr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    itemAttr[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [barItem setTitleTextAttributes:itemAttr forState:UIControlStateNormal];
    barItem.tintColor = [UIColor whiteColor];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//    if (self.viewControllers.count > 0) {
//        if (IOS8) {
//            PTSTabBarViewController *tabBarVc = (PTSTabBarViewController *)self.tabBarController;
//            [UIView animateWithDuration:0.5 animations:^{
//                tabBarVc.tabBar.transform = CGAffineTransformMakeTranslation(0, 49);
//                
//            } completion:^(BOOL finished) {
//                tabBarVc.hidesBottomBarWhenPushed = YES;
//            }];
//        } else {
//            viewController.hidesBottomBarWhenPushed = YES;
//        }
//    }
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}

//- (UIViewController *)popViewControllerAnimated:(BOOL)animated
//{
//    if (IOS8) {
//        [CATransaction begin];
//        [CATransaction setCompletionBlock:^{
//            CGPoint tranPoint = [self.fd_fullscreenPopGestureRecognizer translationInView:self.view];
//            if (tranPoint.x >= ScreenWidth * 0.5 || tranPoint.x == 0) {
//                if (self.viewControllers.count <= 1) {
//                    PTSTabBarViewController *tabBarVc = (PTSTabBarViewController *)self.tabBarController;
//                    tabBarVc.hidesBottomBarWhenPushed = NO;
//                    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
//                        tabBarVc.tabBar.transform = CGAffineTransformMakeTranslation(0, 0);
//                    } completion:^(BOOL finished) {
//                        
//                    }];
//                }
//            }
//            
//        }];
//    }
//    
//    UIViewController *vc = [super popViewControllerAnimated:animated];
//    
//    if (IOS8) {
//        [CATransaction commit];
//    }
//    
//    return vc;
//    
//}

//- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
//{
//    if (IOS8) {
//        if (self.viewControllers.count == 1) {
//            PTSTabBarViewController *tabBarVc = (PTSTabBarViewController *)self.tabBarController;
//            tabBarVc.hidesBottomBarWhenPushed = NO;
//            [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
//                tabBarVc.tabBar.transform = CGAffineTransformMakeTranslation(0, 0);
//            } completion:^(BOOL finished) {
//                
//            }];
//        }
//    }
//}

@end
